<template>
  <el-dialog title="添加引绳或导线" :modelValue="visiable" width="600px" @close="emit('closed')">
    <el-form :model="model" label-width="80px" :inline="false">
      <el-form-item label="类型">
        <el-select v-model="model.wireName" placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="型号">
        <el-input v-model="model.wireStyle">
          <template #prepend>
            <Merge theme="outline" size="18" fill="#333" />
          </template>
        </el-input>
      </el-form-item>

      <el-form-item label="自重比载">
        <el-input v-model="model.wireWeight">
          <template #prepend>
            <IndustrialScales theme="outline" size="18" fill="#333" />
          </template>
          <template #suffix>
            <span class="text-xs">kg/m</span>
          </template>
        </el-input>
      </el-form-item>

      <el-form-item label="破断力">
        <el-input v-model="model.wirePower">
          <template #prepend>
            <Muscle theme="outline" size="18" fill="#333" />
          </template>
          <template #suffix>
            <span class="text-xs">kN</span>
          </template>
        </el-input>
      </el-form-item>

      <el-form-item label="备注">
        <el-input v-model="model.remark">
          <template #prepend>
            <Bookshelf theme="outline" size="18" fill="#333" />
          </template>
        </el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button @click="emit('closed')">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script setup lang="ts">
import useWire from '@/composables/useWire'
import { Bookshelf, IndustrialScales, Merge, Muscle } from '@icon-park/vue-next'
import { reactive } from 'vue'

defineProps<{ visiable: boolean }>()
const emit = defineEmits(['closed'])

const { add } = useWire()

const options = [
  { label: '引绳', value: '引绳' },
  { label: '导线', value: '导线' },
]

const model = reactive<WireModel>({
  wireName: '导线',
  wireStyle: 'LGJ-300/40',
  wireWeight: 3.08,
  wirePower: 1000,
  remark: '1111',
})

async function onSubmit() {
  await add({ ...model })
  emit('closed')
}
</script>

<style></style>
